package mo.leetcode_top;

import mo.common.ListNode;

import java.util.Stack;

public class L234 {

    public boolean isPalindrome(ListNode head) {
        if (head == null) {
            return true;
        }
        ListNode p1 = head;

        Stack<Integer> stack = new Stack<>();
        while (p1 != null) {
            stack.push(p1.val);
            p1 = p1.next;
        }

        p1 = head;
        while (!stack.isEmpty()) {
            if (p1.val != stack.pop()) {
                return false;
            }
            p1 = p1.next;
        }

        return true;

    }

}
